package org.gw.building.repositories;

import org.gw.building.model.Message;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface MessageRepository extends JpaRepository<Message, String> {
	@Query("from Message t where (?1 is null or t.fsnr like ?1) and (?2 is null or t.fsfs =?2) order by t.fssj desc")
	Page<Message> query(String name, String sendType, Pageable pageable);

	Page<Message> findByFbdxInOrderByFssjDesc(List<String> fbdx, Pageable pageable);

	@Transactional
	@Modifying
	int deleteByBizTypeAndBizId(String bizType, String bizId);

	Message findFirstByBizTypeAndBizId(String coursePublishType, String id);

}
